{include file="public/layout" /}
<body>
  <link rel="stylesheet" href="__SKIN__/css/page.css" media="all">
   <div class="layui-fluid">
      <div class="layui-card">
        <div class="head-oper">
          <div class="fl">
            {eq name="'Channeltype@add'|is_check_access" value="1"}
            <a data-url="{:url('Channeltype/add')}" data-type="Channeltype_add" class="layui-btn mt5 ">新增模型</a>
            {/eq}
          </div>
          <div class="fr">
           <!-- {eq name="'Field@arctype_index'|is_check_access" value="1"}
            <a href="{:url('Field/arctype_index')}" class="layui-btn layui-btn-danger layui-btn-xs "><i class="layui-icon layui-icon-set-sm"></i>栏目字段管理</a>
            {/eq}-->
          </div>
        </div>
        <div class="layui-card-body">
          <div class="layui-form layui-border-box layui-table-view house-table" lay-filter="formTest" lay-id="admin-arctype" >
            <div class="layui-table-box">
              <div class="layui-table-body " >
                <table cellspacing="0" cellpadding="0" border="0" class="layui-table layui-form" style="width: 100%" lay-skin="line">
                  <thead >
                    <tr>
                      <th class="w60 tc"> 
                        <div class="layui-table-cell w60 tc" ><span>ID</span></div>
                      </th>
                      <th class="wauto"> 
                        <div class="layui-table-cell wauto" ><span>模型名称</span></div>
                      </th>
                      <th class="w140 tc"> 
                        <div class="layui-table-cell w140 tc"><span>模型标识</span></div>
                      </th>
                      <th class="w100 tc"> 
                        <div class="layui-table-cell w100 tc"><span>类型</span></div>
                      </th>
                      <th class="w80 tc"> 
                        <div class="layui-table-cell w80 tc"><span>启用</span></div>
                      </th>
                      <th class="w80 tc"> 
                        <div class="layui-table-cell w80 tc"><span>排序</span></div>
                      </th>
                      <th class="w180 tc"> 
                        <div class="layui-table-cell w180 tc"><span>操作</span></div>
                      </th>
                    </tr>
                 </thead>
                 <tbody>
                  {empty name="list"}
                    <tr>
                      <td colspan="7" class="no-data tc">
                         没有符合条件的数据
                      </td>
                    </tr>
                  {else/}
                    {foreach name="list" item="vo" key="k" }
                     <tr>
                        <td>
                           <div class="layui-table-cell w60 tc"> {$vo.id} </div>
                        </td>
                        <td>
                            <div class="layui-table-cell wauto">
                                {eq name="'Channeltype@edit'|is_check_access" value="1"}
                                <a href="javascript:void(0);" class="eju-event" data-type="Channeltype_edit" data-url="{:url('Channeltype/edit',array('id'=>$vo['id']))}">{$vo.title}</a>
                                {else /}
                                {$vo.title}
                                {/eq}
                            </div>
                        </td>
                        <td>
                          <div class="layui-table-cell w140 tc" title="{$vo.title}"> 
                            {$vo.nid}
                          </div>
                        </td>
                        <td>
                          <div class="layui-table-cell w100 tc"> 
                            {eq name='$vo.ifsystem' value='1'}
                              系统
                            {else /}
                              自定义
                            {/eq}
                          </div>
                        </td>
                        <td>
                           <div class="layui-table-cell w80 tc">
                              {eq name="'Channeltype@edit'|is_check_access" value="1"}
                                <input type="checkbox" lay-skin="switch" lay-filter="status" data-id="{$vo.id}" data-title="{$vo.title}" value="{$vo.status}" {eq name="$vo['status']" value="1"}checked{/eq} lay-text="是|否">
                              {else /}
                                <input type="checkbox" lay-skin="switch" disabled {eq name="$vo['status']" value='1'}checked{/eq} lay-text="是|否">
                              {/eq}
                           </div>
                        </td>
                        <td>
                          <div class="layui-table-cell w80 tc">
                            {eq name="'Channeltype@edit'|is_check_access" value="1"}
                            <input type="text" value="{$vo.sort_order}" onchange="changeTableVal('channeltype','id','{$vo.id}','sort_order',this);" class="layui-input" onkeyup="this.value=this.value.replace(/[^\d]/g,'');" onpaste="this.value=this.value.replace(/[^\d]/g,'');">
                            {else /}
                            {$vo.sort_order}
                            {/eq}
                          </div>
                         </td>
                        <td>
                           <div class="layui-table-cell w250 tl right-oper"> 
                            {eq name="'Channeltype@edit'|is_check_access" value="1"}
                                <a class="layui-btn btn-edit customvar_edit" data-url="{:url('Channeltype/edit',array('id'=>$vo['id']))}" data-type="Channeltype_edit">编辑</a>
                            {/eq}

                            {eq name="'Channeltype@edit'|is_check_access" value="1"}
                                <a class="layui-btn btn-primary" href="{:url('Field/channel_index',array('channel_id'=>$vo['id']))}">内容字段</a>
                            {/eq}

                            {eq name="'Channeltype@del'|is_check_access" value="1"}
                              {empty name="$vo.ifsystem"}
                                <a href="javascript:void(0);" class="layui-btn btn-primary" data-url="{:url('Channeltype/del')}" data-id="{$vo.id}" data-type="Channeltype_del">删除</a>
                              {else /}
                                <a href="javascript:void(0);" class="layui-btn btn-primary" title='系统模型不能删除' style="color:#ccc; cursor:not-allowed">删除</a> 
                              {/empty}
                            {/eq}
                           </div>
                        </td>
                      </tr>
                    {/foreach}
                  {/empty}
                  </tbody>
                </table>
        </div>
      </div>
      <!--分页-->
     </div>
     </div>
  </div>
 </div>
  <script>
  layui.config({
    base: '__SKIN__/' //静态资源所在路径
    ,version: '{$version}'
  }).extend({
    index: 'lib/index' //主入口模块
  }).use(['index', 'form'], function(){
    var $ = layui.$
    ,form = layui.form;

    form.on('switch(status)', function(data){
        var obj = data.elem;
        if (obj.checked) {
            data.value = 1;
        } else {
            data.value = 0;
        }
        var status = data.value;
        var title = $(obj).attr('data-title');
        var load = layer_loading();
        $.ajax({
            type : 'post',
            url : "{:url('Channeltype/ajax_show')}",
            data : {id:$(obj).attr('data-id'),status:status,_ajax:1},
            dataType : 'json',
            success : function(res){
                layer.close(load); //关闭loading
                if (res.code == 1) {
                    if (0 == res.data.confirm) {
                        layer.msg(res.msg, {icon: 1, time:500}, function(){
                            window.location.reload();
                        });
                    } else {
                        var confirm = layer.confirm(res.msg, {
                            title: false,
                            btn: ['启用','取消'] //按钮
                        }, function(index){
                            layer.close(index);
                            var load = layer_loading();
                            // 确定
                            $.ajax({
                                type : 'post',
                                url : "{:url('Channeltype/ajax_check_tpl')}",
                                data : {id:$(obj).attr('data-id'),status:status,tpltype:res.data.tpltype},
                                dataType : 'json',
                                success : function(res){
                                    layer.close(load); //关闭loading
                                    if(res.code == 1){
                                        layer.msg(res.msg, {icon: 1, time: 500}, function(){
                                            window.location.reload();
                                        });
                                    }else{
                                        showErrorAlert(res.msg);
                                    }
                                },
                                error:function(){
                                    layer.close(load); //关闭loading
                                    showErrorAlert();
                                }
                            })
                        });
                    }
                } else {
                    layer.alert(res.msg, {icon: 5, title: false, closeBtn:false}, function(){
                        window.location.reload();
                    });
                }
            },
            error:function(){
                layer.close(load); //关闭loading
                showErrorAlert();
            }
        });
    });

    /* 触发事件 */
    var active = {
      Channeltype_add: function(){
          var iframes = layer.open({
              type: 2,
              title: '新增模型',
              fixed: true, //不固定
              shadeClose: false,
              shade: 0.3,
              content: $(this).data('url')
          });
          layer.full(iframes);
      }
      ,Channeltype_edit: function(){
          var iframes = layer.open({
              type: 2,
              title: '编辑模型',
              fixed: true, //不固定
              shadeClose: false,
              shade: 0.3,
              content: $(this).data('url')
          });
          layer.full(iframes);
      }
      ,Channeltype_del: function(){
        var obj = this;
        var confirm = layer.confirm('<font color="#ff0000">此操作将会删除与该模型所有相关的数据且不可恢复，请谨慎操作！</font>是否确认删除？', {
            title: false,
            btn: ['确定','取消'] //按钮
        }, function(){
            layer.close(confirm);
            var load = layer_loading();
            // 确定
            $.ajax({
                type : 'post',
                url : $(obj).attr('data-url'),
                data : {del_id:$(obj).attr('data-id'),_ajax:1},
                dataType : 'json',
                success : function(res){
                    layer.close(load); //关闭loading
                    if(res.code == 1){
                        layer.msg(res.msg, {icon: 1, time: 500}, function(){
                            window.location.reload();
                        });
                    }else{
                        showErrorAlert(res.msg);
                    }
                },
                error:function(){
                    layer.close(load); //关闭loading
                    showErrorAlert();
                }
            })
        }, function(index){
          layer.close(index);
        });
        return false;
      }
    };

    $('.layui-btn,.eju-event').on('click', function(){
      var type = $(this).data('type');
      active[type] && active[type].call(this);
    });

  });

  </script>
{include file="public/footer" /}